{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 首先 import 必要的模块\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "train = pd.read_csv(\"FE_pima-indians-diabetes.csv\")\n",
    "y_train = train['Target'];\n",
    "X_train = train.drop([\"Target\"], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['pregnants', 'Plasma_glucose_concentration', 'blood_pressure',\n",
      "       'Triceps_skin_fold_thickness', 'serum_insulin', 'BMI',\n",
      "       'Diabetes_pedigree_function', 'Age'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "# 保存特征名字以备后用（可视化）\n",
    "feat_names = X_train.columns ;\n",
    "print(feat_names);\n",
    "#sklearn的学习器大多之一稀疏数据输入，模型训练会快很多\n",
    "#查看一个学习器是否支持稀疏数据，可以看fit函数是否支持: X: {array-like, sparse matrix}.\n",
    "#可自行用timeit比较稠密数据和稀疏数据的训练时间\n",
    "from scipy.sparse import csr_matrix\n",
    "X_train = csr_matrix(X_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "默认参数的Logistic Regression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "logloss of each fold is:  [0.49262063 0.50570133 0.45515617]\n",
      "cv logloss is: 0.48449271041943326\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "E:\\anaconda3\\lib\\site-packages\\sklearn\\linear_model\\logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
      "  FutureWarning)\n",
      "E:\\anaconda3\\lib\\site-packages\\sklearn\\linear_model\\logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
      "  FutureWarning)\n",
      "E:\\anaconda3\\lib\\site-packages\\sklearn\\linear_model\\logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
      "  FutureWarning)\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import LogisticRegression\n",
    "lr = LogisticRegression()\n",
    "\n",
    "# 交叉验证用于评估模型性能和进行参数调优（模型选择）\n",
    "#分类任务中交叉验证缺省是采用StratifiedKFold\n",
    "#采用5折交叉验证\n",
    "from sklearn.model_selection import cross_val_score\n",
    "loss = cross_val_score(lr, X_train, y_train, cv=5, scoring='neg_log_loss')\n",
    "#%timeit loss_sparse = cross_val_score(lr, X_train_sparse, y_train, cv=3, scoring='neg_log_loss')\n",
    "print ('logloss of each fold is: ',-loss)\n",
    "print ('cv logloss is:', -loss.mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.4820287373783357\n",
      "{'C': 1, 'penalty': 'l2'}\n"
     ]
    }
   ],
   "source": [
    "#正则化的 Logistic Regression及参数调优\n",
    "penaltys = ['l1', 'l2'];\n",
    "Cs = [0.001, 0.01, 0.1, 1, 10, 100, 1000];\n",
    "tuned_parameters = dict(penalty=penaltys, C=Cs);\n",
    "lr_penalty = LogisticRegression(solver='liblinear');\n",
    "grid = GridSearchCV(lr_penalty, tuned_parameters, cv=5, scoring='neg_log_loss');\n",
    "grid.fit(X_train, y_train);\n",
    "\n",
    "# examine the best model\n",
    "print(-grid.best_score_);\n",
    "print(grid.best_params_);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "E:\\anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:125: FutureWarning: You are accessing a training score ('mean_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n",
      "E:\\anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:125: FutureWarning: You are accessing a training score ('std_train_score'), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True\n",
      "  warnings.warn(*warn_args, **warn_kwargs)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3Xl4lPW5//H3PQlJWMIeEEgURFxYBMy4IGgVNxQrKoRqN7X1aI9b29Pa6jmtC9Yejz09v9oWW5fSWltFwF2ouKDihpIgOy6AC2HRsO9ku39/zCAxhMxkGZ6Zyed1XXNl5pnvM3M/IPn4bPfX3B0REZH6hIIuQEREkp/CQkREYlJYiIhITAoLERGJSWEhIiIxKSxERCQmhYWIiMSksBARkZgUFiIiElNm0AU0l65du3rv3r2DLkNEJKWUlJSsd/e8WOMSGhZmNgq4B8gAHnT3u2q9//+A06Mv2wDd3L1j9L3LgF9E3/uVuz9U33f17t2b4uLi5ixfRCTtmdmn8YxLWFiYWQYwETgLKAXmmtkz7r507xh3/3GN8dcDQ6PPOwO3AmHAgZLoupsSVa+IiBxYIs9ZnAAsd/eV7l4OTAbG1DP+UuDR6PNzgBfdfWM0IF4ERiWwVhERqUciw6IXsKrG69Losv2Y2WFAH2BWQ9Y1s6vMrNjMisvKypqlaBER2V8iz1lYHcsO1A/9EmCau1c1ZF13vx+4HyAcDqvXuoh8qaKigtLSUnbv3h10KUkhJyeH/Px8WrVq1aj1ExkWpUBBjdf5wJoDjL0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XRcBfwDygM3AfHc/J9iq4mdm5wG/Y1/n5TsDLqnRzOxR4DQiHU4/B251978EWlQjmNkI4HVgEZF/7wD/6e4zgquqcczsWOAhIv99hYAp7j4hId+lsBARkVh0GEpERGJSWIiISEwKCxERiUlhISIiMSksREQkJoWFSAOY2fbYo+pdf5qZHR593s7M7jOzFdGOobPN7EQzy4o+b1E3zUpyU1iIHCRmNgDIcPeV0UUPEmnM18/dBwCXA12jTQdfBr4RSKEidVBYiDSCRfwm2sNqkZl9I7o8ZGb3RvcUnjOzGWY2Lrrat4Cno+P6AicCv3D3aoBod9rp0bFPRceLJAXt5oo0zsXAEGAwkTua55rZbGA40BsYBHQj0v56UnSd4cCj0ecDiNyNXnWAz18MHJ+QykUaQXsWIo0zAng02vHzc+A1Ir/cRwBT3b3a3dcBr9RYpwdQFs+HR0OkPDo5j0jgFBYijVNX+/H6lgPsAnKiz5cAg82svn+D2cDuRtQm0uwUFiKNMxv4RnTimTzgVOBdItNajo2eu+hOpPHeXsuAIwDcfQVQDNwe7YKKmfXbO4eHmXUByty94mBtkEh9FBYijfMksBBYAMwCfhY97PQ4kXksFhOZN/wdYEt0nel8NTyuBA4BlpvZIuAB9s13cTqQcl1QJX2p66xIMzOzdu6+Pbp38C4w3N3XRecbeCX6+kAntvd+xhPAzSk8/7ikGV0NJdL8notOSJMF3BHd48Ddd5nZrUTm4f7sQCtHJ0p6SkEhyUR7FiIiEpPOWYiISEwKCxERiUlhISIiMSksREQkJoWFiIjEpLAQEZGY/j/TuaueRPTtWAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot CV误差曲线\n",
    "test_means = grid.cv_results_['mean_test_score'];\n",
    "test_stds = grid.cv_results_['std_test_score'];\n",
    "train_means = grid.cv_results_['mean_train_score'];\n",
    "train_stds = grid.cv_results_['std_train_score'];\n",
    "\n",
    "# plot results\n",
    "n_Cs = len(Cs);\n",
    "number_penaltys = len(penaltys);\n",
    "test_scores = np.array(test_means).reshape(n_Cs, number_penaltys);\n",
    "train_scores = np.array(train_means).reshape(n_Cs, number_penaltys);\n",
    "test_stds = np.array(test_stds).reshape(n_Cs, number_penaltys);\n",
    "train_stds = np.array(train_stds).reshape(n_Cs, number_penaltys);\n",
    "x_axis = np.log10(Cs);\n",
    "for i, value in enumerate(penaltys):\n",
    "    # pyplot.plot(log(Cs), test_scores[i], label= 'penalty:'   + str(value))\n",
    "    plt.errorbar(x_axis, -test_scores[:, i], yerr=test_stds[:, i], label=penaltys[i] + ' Test');\n",
    "plt.figure(1);\n",
    "plt.legend();\n",
    "plt.xlabel('log(C)');\n",
    "plt.ylabel('logloss');plt.show();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1: array([[-0.69314718, -0.64643499, -0.49334691, -0.49423639, -0.49550342,\n",
      "        -0.49564827, -0.49565918],\n",
      "       [-0.69314718, -0.65138433, -0.51620914, -0.5092952 , -0.50875142,\n",
      "        -0.50871109, -0.50870588],\n",
      "       [-0.69314718, -0.64570415, -0.47822778, -0.48179949, -0.48313488,\n",
      "        -0.48327802, -0.48329393],\n",
      "       [-0.69314718, -0.64433664, -0.45405821, -0.43661789, -0.43569075,\n",
      "        -0.43560309, -0.43560043],\n",
      "       [-0.69314718, -0.64757466, -0.49692359, -0.48811094, -0.4880955 ,\n",
      "        -0.48810274, -0.48810074]])}\n"
     ]
    }
   ],
   "source": [
    "#用LogisticRegressionCV实现正则化的 Logistic Regression\n",
    "#使用l1正则\n",
    "from sklearn.linear_model import LogisticRegressionCV\n",
    "Cs = [1e-3, 1e-2, 1e-1, 1, 10, 100, 1000];\n",
    "lrcv_L1 = LogisticRegressionCV(Cs=Cs, cv=5, scoring='neg_log_loss', penalty='l1',\\\n",
    "                               solver='liblinear',\n",
    "                               multi_class='ovr');\n",
    "lrcv_L1.fit(X_train, y_train);\n",
    "\n",
    "print(lrcv_L1.scores_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[array([[-0.69314718, -0.64643499, -0.49334691, -0.49423639, -0.49550342,\n",
      "        -0.49564827, -0.49565918],\n",
      "       [-0.69314718, -0.65138433, -0.51620914, -0.5092952 , -0.50875142,\n",
      "        -0.50871109, -0.50870588],\n",
      "       [-0.69314718, -0.64570415, -0.47822778, -0.48179949, -0.48313488,\n",
      "        -0.48327802, -0.48329393],\n",
      "       [-0.69314718, -0.64433664, -0.45405821, -0.43661789, -0.43569075,\n",
      "        -0.43560309, -0.43560043],\n",
      "       [-0.69314718, -0.64757466, -0.49692359, -0.48811094, -0.4880955 ,\n",
      "        -0.48810274, -0.48810074]])]\n",
      "[0.69314718 0.64708695 0.48775313 0.48201198 0.48223519 0.48226864\n",
      " 0.48227203]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAH5JJREFUeJzt3Xl0XPWZ5vHvW5Il2ZIlL5Llkm2wDQZs4xIEYZKYacJuoFiydAKdyUAnZJmEJn2mJx0yyTQn0J3Qp7vT6YV0AoQMM51ACCQE2wSzQ2ICWAa828R2AAu8yPsqy5Le+aOuoSzLqtJydWt5PufUoerWvVXvPdj1+P7u797X3B0REZHexKIuQEREcp/CQkREMlJYiIhIRgoLERHJSGEhIiIZKSxERCQjhYWIiGSksBARkYwUFiIiklFpmB9uZnOBfwFKgHvc/Y5u7/8zcH7wcgQwzt1HBe9dD3wreO9v3f2+3r6rtrbWJ0+eP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wkJERDJSWIiISEYKCxERyUhhIdIHZrYv81q9bv+QmU0NnleZ2Y/MbH1wx9AXzOwcMysLnhfVRbOS2xQWIkPEzGYCJe6+IVh0D6kb801z95nADUBtcNPBp4FPRVKoSA8UFiL9YCn/ENzDarmZfSpYHjOzHwRHCvPN7DEz+0Sw2aeBXwfrnQScA3zL3bsAgrvTLgjWfSRYXyQn6DBXpH8+BpwBNJK6onmxmb0AzAEmA7OAcaRuf31vsM0c4P7g+UxSV6N3HufzVwBnh1K5SD/oyEKkf84F7g/u+LkFeJ7Uj/u5wC/cvcvdNwPPpm0TB1qz+fAgRNqD5jwikVNYiPRPT7cf7205wEGgIni+Emg0s97+DpYDbf2oTWTQKSxE+ucF4FNB45k64E+AV0i1tfx4cO6intSN945YDZwM4O7rgWbg28FdUDGzaUd6eJjZWKDV3Q8P1Q6J9EZhIdI/vwKWAUuBZ4C/DoadHibVx2IFqb7hLwO7g20WcHR43AiMB9aZ2XLgbt7vd3E+kHd3QZXCpbvOigwyM6ty933B0cErwBx33xz0G3g2eH28E9tHPuOXwDfyuP+4FBjNhhIZfPODhjRlwO3BEQfuftDMbiXVh/vt420cNEp6REEhuURHFiIikpHOWYiISEYKCxERyUhhISIiGSksREQkI4WFiIhkpLAQEZGM/j+sCMytvZ2UswAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 0.48201198400501327\n"
     ]
    }
   ],
   "source": [
    "\n",
    "n_Cs = len(Cs);\n",
    "n_classes = 1;\n",
    "#scores = np.zeros((n_classes, n_Cs));\n",
    "scores = [];\n",
    "lst2 = list(lrcv_L1.scores_.values());print(lst2);\n",
    "\n",
    "scores = np.mean(lst2,axis = 0);\n",
    "mse_mean = -np.mean(scores, axis=0);print(mse_mean);\n",
    "\n",
    "plt.figure(2);\n",
    "plt.plot(np.log10(Cs), mse_mean.reshape(n_Cs, 1));\n",
    "plt.xlabel('log(C)');\n",
    "plt.ylabel('logloss');\n",
    "plt.show();\n",
    "\n",
    "best_C = np.argmin(mse_mean);\n",
    "best_score = np.min(mse_mean);\n",
    "print(Cs[best_C], best_score)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
